package com.googlecode.stockhamster.client.swing;

import java.awt.BorderLayout;
import java.net.MalformedURLException;

import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import com.googlecode.stockhamster.Constant;
import com.googlecode.stockhamster.stockstat.IStockStat;
import com.googlecode.stockhamster.utils.XFireStub;

public class StockStatPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6281299534336391431L;

	private IStockStat status;

	private JList stockList;
	private HistoryView stockView;

	public StockStatPanel() throws MalformedURLException {
		status = new XFireStub<IStockStat>(Constant.stockStatUrl,
				IStockStat.class).getStub();

		setLayout(new BorderLayout());
		Integer stockId[] = status.getStocks();
		String stockName[] = new String[stockId.length];
		for (int i = 0; i < stockId.length; i++)
			stockName[i] = status.getName(stockId[i]);
		stockList = new JList(stockName);
		stockList.addListSelectionListener(new ListSelectionListener() {
			@Override
			public void valueChanged(ListSelectionEvent e) {
				stockView.showStock((String) stockList.getSelectedValue(),
						false, true);
			}
		});
		stockView = new HistoryView(status);
		add(stockList, BorderLayout.WEST);
		add(stockView, BorderLayout.CENTER);
	}
}
